package com.csu.backmanagesys.Service.impl;

import com.csu.backmanagesys.Domain.Item;
import com.csu.backmanagesys.Mapper.ItemMapper;
import com.csu.backmanagesys.Service.ItemService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Resource
    private ItemMapper ItemMapper;

    @Override
    public List<Item> selectItem(){
        return ItemMapper.selectItem();
    }

    @Override
    public List<Item> selectItemById(String itemId){
        return ItemMapper.selectItemById(itemId);
    }

    @Override
    public List<Item> fuzzySelectItem(String param){return ItemMapper.fuzzySelectItem(param);};

    @Override
    public void insertItem(String itemId, String productId, BigDecimal listPrice, BigDecimal unitCost, int supplierId, String status, String attribute1, String attribute2, String attribute3, String attribute4, String attribute5) {
        ItemMapper.insertItem(itemId,productId,listPrice,unitCost,supplierId,status,attribute1,attribute2,attribute3,attribute4,attribute5);
    }

    @Override
    public void insertInventory(String itemId, int qty) {
        ItemMapper.insertInventory(itemId , qty);
    }

    @Override
    public  void deleteItem(String itemId){
        ItemMapper.deleteItem(itemId);
    }

    @Override
    public  void updateItem(
            String itemId,
            String productId,
            BigDecimal listPrice,
            BigDecimal unitCost,
            int supplierId,
            String status,
            String attribute1,
            String attribute2,
            String attribute3,
            String attribute4,
            String attribute5
    ){
        ItemMapper.updateItem(itemId,productId,listPrice,unitCost,supplierId,status,attribute1,attribute2,attribute3,attribute4,attribute5);
    };

    @Transactional
    @Override
    public void updateItemQty(String itemId, int stockCount) {
        ItemMapper.selectItemById(itemId);
        ItemMapper.updateItemQty(itemId , stockCount);
    }
}
